var grid;
var searchobj;

function showFlowChart(_contextCaseId, _contextProcessId, _templateId, _contextActivityId, appType) {
  var showHastenButton = 'true';
  var supervisorsId = "";
  var isTemplate = false;
  var operationId = "";
  var senderName = "";
  var openType = getA8Top();

  if (_templateId && "undefined" != _templateId) {
    isTemplate = true;
  }

  showWFCDiagram(openType, _contextCaseId, _contextProcessId, isTemplate, showHastenButton, supervisorsId, window, appType, false, _contextActivityId, operationId, null, senderName);
}

$(function () {
  //初始化布局
  new MxtLayout({
    'id': 'layout',
    'northArea': {
      'id': 'north',
      'height': 40,
      'sprit': false,
      'border': false
    },
    'centerArea': {
      'id': 'center',
      'border': false,
      'minHeight': 20
    }
  });
  var toolbar = [{
    id: "listPending",
    name: i18nPendingLable,
    //未办结
    className: "ico16 no_through_ico_16",
    selected: true,
    click: listPending
  }, {
    id: "listDone",
    name: i18nDoneLable,
    //已办结
    className: "ico16 gone_through_16",
    click: listDone
  }, {
    id: "handling",
    name: i18nHandingLable,
    //办理情况
    className: "ico16 handling_16",
    click: handling
  }];

  if (app == '4') {
    //根据配置的枚举展示查询条件
    var arr = new Array();

    if (secretLevelList != "") {
      try {
        arr = eval("(" + secretLevelList + ")");
      } catch (e) {}

      var secretLevelOptions = new Array();

      for (var i = 0; i < arr.length; i++) {
        secretLevelOptions[i] = {
          text: arr[i].showvalue,
          value: arr[i].enumvalue
        };
      }
    }

    if (urgentLevelList != "") {
      try {
        arr = eval("(" + urgentLevelList + ")");
      } catch (e) {}

      var urgentLevelOptions = new Array();

      for (var i = 0; i < arr.length; i++) {
        urgentLevelOptions[i] = {
          text: arr[i].showvalue,
          value: arr[i].enumvalue
        };
      }
    }

    toolbar.push({
      id: "stepbackRecord",
      name: $.i18n('collaboration.workflow.label.repealStepback'),
      //回退记录
      className: "ico16 toback_16 ",
      click: listSBRecord
    });
  }

  if (docPlugin && app != '4') {
    toolbar.push({
      id: "archivedModifyHistory",
      name: i18nEdocArchiveModifyLable,
      //归档公文修改日志
      className: "ico16 revision_history_16",
      click: showArchiveModifyLog_iframe
    });
  }

  toolbar.push({
    id: "deleteSupervise",
    name: i18nDeleteLable,
    //删除
    className: "ico16 del_16",
    click: deleteSupervise
  }); //工具栏

  var toolbars = $("#toolbars").toolbar({
    borderTop: false,
    borderLeft: false,
    borderRight: false,
    toolbar: toolbar
  }); //搜索框

  if (app != '4') {
    //查询条件
    var condition = new Array();
    condition.push({
      id: 'title',
      name: 'title',
      type: 'input',
      text: i18nSubjectLable,
      //标题
      value: 'title'
    });
    condition.push({
      id: 'importantLevel',
      name: 'importantLevel',
      type: 'select',
      text: i18nImportanceLable,
      //重要程度
      value: 'importantLevel',
      items: [{
        text: i18nImportancePutongLable,
        //普通
        value: '1'
      }, {
        text: i18nImportanceZhongyaoLable,
        //重要
        value: '2'
      }, {
        text: i18nImportancefeichangZhongyaoLable,
        //非常重要
        value: '3'
      }]
    });
    condition.push({
      id: 'sender',
      name: 'sender',
      type: 'input',
      text: i18nsenderLable,
      //发起人
      value: 'sender'
    });
    condition.push({
      id: 'sendDate',
      name: 'sendDate',
      type: 'datemulti',
      text: i18nsendtimeLable,
      //发起时间
      value: 'sendDate',
      ifFormat: '%Y-%m-%d',
      dateTime: false
    });
    condition.push({
      id: 'deadlineDatetime',
      name: 'deadlineDatetime',
      type: 'datemulti',
      text: i18ncycleLable,
      value: 'deadlineDatetime',
      ifFormat: '%Y-%m-%d',
      dateTime: false
    }); //扫一扫

    if (hasBarCode == "true") {
      condition.push({
        id: 'saoyisao',
        name: 'saoyisao',
        type: 'barcode',
        text: i18nsaoyisaoLable,
        value: 'barcode'
      });
    }

    searchobj = $.searchCondition({
      top: 7,
      right: 10,
      searchHandler: function searchHandler() {
        searchFunc();
      },
      conditions: condition
    });
  } else {
    searchobj = $.searchCondition({
      top: 7,
      right: 10,
      searchHandler: function searchHandler() {
        searchFunc();
      },
      conditions: [{
        id: 'title',
        name: 'title',
        type: 'input',
        text: edoc_supervise_title,
        //公文标题
        value: 'title'
      }, {
        id: 'docMark',
        name: 'docMark',
        type: 'input',
        text: wordno_label,
        //公文文号
        value: 'docMark'
      }, {
        id: 'docInMark',
        name: 'docInMark',
        type: 'input',
        text: wordinno_label,
        //内部文号
        value: 'docInMark'
      }, {
        id: 'sender',
        name: 'sender',
        type: 'input',
        text: i18nsenderLable,
        //发起人
        value: 'sender'
      }, {
        id: 'sendDate',
        name: 'sendDate',
        type: 'datemulti',
        text: i18nsendtimeLable,
        //发起时间
        value: 'sendDate',
        ifFormat: '%Y-%m-%d',
        dateTime: false
      }, {
        id: 'supervisors',
        name: 'supervisors',
        type: 'input',
        text: edoc_supervise_supervisor,
        //督办人
        value: 'supervisors'
      }, {
        id: 'awakeDate',
        name: 'awakeDate',
        type: 'datemulti',
        text: edoc_supervise_deadline,
        //督办期限
        value: 'awakeDate'
      }, {
        id: 'secretLevel',
        name: 'secretLevel',
        type: 'select',
        text: secretlevel_simple,
        //密级
        value: 'secretLevel',
        items: secretLevelOptions
      }, {
        id: 'urgentLevel',
        name: 'urgentLevel',
        type: 'select',
        text: urgentlevel,
        //紧急程度
        value: 'urgentLevel',
        items: urgentLevelOptions
      }, {
        id: 'deadlineDatetime',
        name: 'deadlineDatetime',
        type: 'datemulti',
        text: i18ncycleLable,
        value: 'deadlineDatetime',
        ifFormat: '%Y-%m-%d',
        dateTime: false
      }, {
        id: 'edocType',
        name: 'edocType',
        type: 'select',
        text: sorttype_label,
        //类别
        value: 'edocType',
        items: [{
          text: docmark_inner_send,
          //发文
          value: '0'
        }, {
          text: docmark_inner_receive,
          //收文
          value: '1'
        }, {
          text: docmark_inner_signandreport,
          //签报
          value: '2'
        }]
      }]
    });
  } //定义列表栏


  var colModel = new Array();
  colModel.push({
    display: 'id',
    name: 'id',
    width: 'smallest',
    sortable: false,
    type: 'checkbox',
    align: 'center'
  });

  if (app != '4') {
    var width = 'big';

    if (superviseStatus == '1') {
      width = 'big';
    } //标题 


    colModel.push({
      display: i18nSubjectLable,
      name: 'title',
      width: width,
      sortable: true
    }); //发起人 

    colModel.push({
      display: i18nsenderLable,
      name: 'senderName',
      width: 'small',
      sortable: true
    }); //发起时间

    colModel.push({
      display: i18nsendtimeLable,
      name: 'sendDate',
      width: 'medium',
      cutsize: 10,
      sortable: true
    });

    if (superviseStatus == '0' || superviseStatus == '') {
      //未办结
      colModel.push({
        display: currentNodesInfo_label,
        //当前处理人信息
        name: 'currentNodesInfo',
        width: 'medium',
        sortable: true
      });
    }

    colModel.push({
      display: process_cycle_label,
      //流程期限    
      name: 'deadlineName',
      width: 'medium',
      sortable: true
    });
    colModel.push({
      display: supervise_col_deadline,
      //督办期限       
      name: 'awakeDate',
      width: 'medium',
      sortable: true
    });
    colModel.push({
      display: supervise_hasten_label,
      //催办
      name: 'count',
      width: 'small',
      sortable: true
    }); //已办结 没有'流程'

    if (superviseStatus !== '1') {
      colModel.push({
        display: supervise_form_bind_flow_label,
        //流程 
        name: '_workflowbutton',
        width: 'small'
      });
    }

    colModel.push({
      display: supervise_col_description,
      //督办摘要
      name: '_summarybutton',
      width: 'small'
    });
  } else {
    var width = 'big';

    if (superviseStatus == '1') {
      width = 'big';
    }

    colModel.push({
      display: sorttype_label,
      //公文类别
      name: 'appName',
      width: 'small',
      sortable: true
    }); //文件标题

    var titleLength = "big";

    if (isG6 == "true") {
      titleLength = "big";
    }

    colModel.push({
      display: edoc_supervise_title,
      name: 'title',
      width: titleLength,
      sortable: true
    }); //发起人 

    colModel.push({
      display: i18nsenderLable,
      name: 'senderName',
      width: 'small',
      sortable: true
    }); //发起时间

    colModel.push({
      display: i18nsendtimeLable,
      name: 'sendDate',
      width: 'medium',
      cutsize: 10,
      sortable: true
    });

    if (superviseStatus == '0' || superviseStatus == '') {
      //未办结
      colModel.push({
        display: currentNodesInfo_label,
        //当前处理人信息
        name: 'currentNodesInfo',
        width: 'medium',
        sortable: true
      });
    }

    colModel.push({
      display: edoc_supervise_supervisor,
      //督办人
      name: 'supervisors',
      width: 'small',
      //cutsize : 10,
      sortable: true
    });
    colModel.push({
      display: process_cycle_label,
      //流程期限    
      name: 'deadlineName',
      width: 'medium',
      sortable: true
    });
    colModel.push({
      display: supervise_col_deadline,
      //督办期限    
      name: 'awakeDate',
      width: 'medium',
      sortable: true
    }); //催办

    colModel.push({
      display: supervise_hasten_label,
      name: 'count',
      width: 'small',
      sortable: true
    }); //已办结 没有'流程'

    if ("${ctp:escapeJavascript(param.status)}" !== '1') {
      colModel.push({
        display: supervise_form_bind_flow_label,
        //流程 
        name: 'processDescBy',
        width: 'small'
      });
    }

    colModel.push({
      display: supervise_col_description,
      //督办摘要
      name: 'description',
      width: 'medium'
    });
  }

  var xyms = true; //定义列表

  var _managerName = "superviseManager";
  var _managerMethod = "getSuperviseList4App";
  var _callBackFun = rend;
  grid = $("#superviseList").ajaxgrid({
    colModel: colModel,
    click: dbclickRow,
    render: _callBackFun,
    height: 200,
    parentId: $('.layout_center').eq(0).attr('id'),
    showTableToggleBtn: true,
    vChange: true,
    gridType: 'autoGrid',
    vChangeParam: {
      overflow: "hidden",
      autoResize: false //表格下方是否自动显示

    },
    isHaveIframe: true,
    slideToggleBtn: true,
    customId: "_supervise_grid_list_app_" + app,
    customize: true,
    onSuccess: function onSuccess() {
      xyms = false;
      $('#summary').attr("src", _ctxPath + "/collaboration/listDesc.do?method=listDesc&type=listSupervise&size=" + grid.p.total + CsrfGuard.getUrlSurffix());
    },
    managerName: _managerName,
    managerMethod: _managerMethod
  });

  if (xyms) {
    $('#summary').attr("src", _ctxPath + "/collaboration/listDesc.do?method=listDesc&type=listSupervise&size=0" + CsrfGuard.getUrlSurffix());
  } //初始化列表数据


  var obj = new Object();
  obj.app = app;
  var status = superviseStatus;

  if (status == '' || status == '0') {
    //默认为 '未办结'
    obj.status = '0';
    $('#status').val('0'); //隐藏工具栏最右侧'|'标识

    $($("#toolbars div div em")[5]).hide();
    toolbars.unselected('listDone');
    toolbars.selected('listPending'); //初始化化时默认查询为'未办结'的数据，所以隐藏'删除'按钮

    toolbars.hideBtn('deleteSupervise'); //归档公文修改日志按钮隐藏

    toolbars.hideBtn('archivedModifyHistory');
    obj.templeteIds = templeteIds;

    if (window.location.href.indexOf("condition=templeteAll&templeteAll=templeteAll") != -1) {
      obj.templeteAll = "templeteAll";
    }
  } else {
    obj.status = status;
    $('#status').val(status);
    $($("#toolbars div div em")[5]).show();
    toolbars.showBtn('deleteSupervise'); //公文已办结显示归档公文修改日志的按钮

    if (app == '4') {
      toolbars.showBtn('archivedModifyHistory');
    } else {
      toolbars.hideBtn('archivedModifyHistory');
    }

    toolbars.unselected('listPending');
    toolbars.selected('listDone');
    obj.templeteIds = templeteIds;
  }

  $("#superviseList").ajaxgridLoad(obj);
  var _urlp = window.location.href;

  if ((_urlp.indexOf("srcFrom=bizconfig") != -1 || _urlp.indexOf("templeteAll=templeteAll") != -1 || _urlp.indexOf("templeteCategory=") != -1 || '${isShowRecord}' == 'true') && _urlp.indexOf("app=4") == -1) {
    toolbars.hideBtn('repealRecord');
    toolbars.hideBtn('stepbackRecord');
    isShowRecord = true;
  }
}); //ready 结束
//搜索框执行的动作

function searchFunc(flag) {
  var choose = $('#' + searchobj.p.id).find("option:selected").val();

  if (grid.p.total == 1 && flag) {
    window.location.reload();
    return;
  }

  var o = new Object();

  if (app != '4') {
    //协同
    var val = searchobj.g.getReturnValue();

    if (val !== null) {
      var obj = getSearchValueObj();
      $("#superviseList").ajaxgridLoad(obj);
    }
  } else {
    //公文
    if (choose === 'title') {
      o.title = $('#title').val();
    } else if (choose === 'docMark') {
      o.docMark = $('#docMark').val();
    } else if (choose === 'docInMark') {
      o.docInMark = $('#docInMark').val();
    } else if (choose === 'sender') {
      o.sender = $('#sender').val();
    } else if (choose === 'sendDate') {
      var fromDate = $('#from_' + choose).val();
      var toDate = $('#to_' + choose).val();
      o.sendDate = '';
      o.begin_sendDate = fromDate;
      o.end_sendDate = toDate;
    } else if (choose === 'supervisors') {
      o.supervisors = $('#supervisors').val();
    } else if (choose === 'awakeDate') {
      var fromDate = $('#from_' + choose).val();
      var toDate = $('#to_' + choose).val();
      o.awakeDate = '';
      o.begin_awakeDate = fromDate;
      o.end_awakeDate = toDate;
    } else if (choose === 'keywords') {
      o.keywords = $('#keywords').val();
    } else if (choose === 'secretLevel') {
      o.secretLevel = $('#secretLevel').val();
    } else if (choose === 'urgentLevel') {
      o.urgentLevel = $('#urgentLevel').val();
    } else if (choose === 'deadlineDatetime') {
      //流程期限
      var fromDate = $('#from_' + choose).val();
      var toDate = $('#to_' + choose).val();
      var date = fromDate + '#' + toDate;
      o.deadlineDatetime = '';
      o.begin_deadlineDatetime = fromDate;
      o.end_deadlineDatetime = toDate;

      if (fromDate != "" && toDate != "" && fromDate > toDate) {
        $.alert(collaboration_rule_date); //开始时间不能早于结束时间

        return;
      }
    } else if (choose === 'edocType') {
      o.edocType = $('#edocType').val();
    }

    var val = searchobj.g.getReturnValue();

    if (val !== null) {
      o.status = $('#status').val();
      o.app = app;
      o.templeteIds = templeteIds;
      $("#superviseList").ajaxgridLoad(o);
    }
  }
} //定义setTimeout执行方法


var TimeFn = null; //定义列表单击事件

function toDetailPage(data, rowIndex, colIndex) {
  grid.grid.resizeGrid(105);
  var url = "";
  var callerResponder = new CallerResponder();

  var _superviseManager = new superviseManager();

  var obj = new Object();
  obj.objId = data.summaryId;
  obj.openFrom = "supervise";
  obj.appName = data.appName;

  var reBack = _superviseManager.checkSuperviseIsCancel(obj);

  if (reBack) {
    $.alert(reBack);
    return;
  }

  var _affairId = getSenderAffairId(data.summaryId);

  url = _ctxPath + "/" + data.detailPageUrl + "&affairId=" + _affairId + "&summaryId=" + data.summaryId + "&openFrom=supervise&type=" + data.status; // 取消上次延时未执行的方法

  clearTimeout(TimeFn); //执行延时

  TimeFn = setTimeout(function () {
    $('#summary')[0].src = url;
  }, 300);
} //双击事件


function dbclickRow(data, rowIndex, colIndex) {
  // 取消上次延时未执行的方法
  clearTimeout(TimeFn);
  var url = "";
  var callerResponder = new CallerResponder();

  var _superviseManager = new superviseManager();

  var obj = new Object();
  obj.objId = data.summaryId;
  obj.openFrom = "supervise";

  var reBack = _superviseManager.checkSuperviseIsCancel(obj);

  if (reBack) {
    $.alert(reBack);
    return;
  }

  var _affairId = getSenderAffairId(data.summaryId);

  url = _ctxPath + "/" + data.detailPageUrl + "&affairId=" + _affairId + "&summaryId=" + data.summaryId + "&openFrom=supervise&type=" + data.status;
  var title = data.subject;
  doubleClick(url, escapeStringToHTML(title));
  grid.grid.resizeGridUpDown('down'); //页面底部说明加载

  $('#summary').attr("src", _ctxPath + "/collaboration/listDesc.do?method=listDesc&type=listSupervise&size=" + grid.p.total + CsrfGuard.getUrlSurffix());
} //未办结


function listPending() {
  var url = _ctxPath + "/supervise/supervise.do?method=listSupervise&app=" + app + "&templeteIds=" + templeteIds + "&status=0&srcFrom=" + srcFrom;
  window.location.href = url + "&isShowRecord=" + isShowRecord;
} //撤销记录


function listRepealRecord() {
  var url = _ctxPath + "/supervise/supervise.do?method=listRecord&app=" + app + "&record=repealRecord&openFrom=supervise";
  url = addUrlPath(url);
  window.location.href = url;
} //回退记录


function listSBRecord() {
  var url = _ctxPath + "/supervise/supervise.do?method=listRecord&app=" + app + "&record=stepBackRecord&openFrom=supervise";
  url = addUrlPath(url);
  window.location.href = url;
} //已办结


function listDone() {
  var url = _ctxPath + "/supervise/supervise.do?method=listSupervise&app=" + app + "&templeteIds=" + templeteIds + "&status=1&srcFrom=" + srcFrom;
  window.location.href = url + "&isShowRecord=" + isShowRecord;
} //办理情况 


function handling() {
  showAffair();
} //删除已办结记录


function deleteSupervise() {
  var rows = grid.grid.getSelectRows();
  var len = rows.length;
  var str = "";

  if (recordType == "stepBackRecord" || recordType == "repealRecord") {
    for (var i = 0; i < len; i++) {
      str += rows[i].id;
      str += ",";
    }

    if (len === 0) {
      //请选择一条督办记录!
      $.alert(collaboration_workflow_label_pleaseChoose);
      return false;
    }

    str = str.substring(0, str.length - 1);
    $.confirm({
      'msg': collaboration_workflow_label_sureDelete,
      ok_fn: function ok_fn() {
        var tm = new traceWorkflowManager();
        var tranObj = new Object();
        tranObj.ids = str;
        tranObj.app = app;
        tm.deleteTraceWorkflows(tranObj, {
          success: function success() {
            for (var i = 0; i < rows.length; i++) {
              try {
                var _affairId = getSenderAffairId(rows[i].summaryId);

                closeOpenMultyWindow(_affairId);
              } catch (e) {}

              ;
            } //刷新列表


            searchFunc('delete');
          },
          error: function error(request, settings, e) {
            $.alert(e);
          }
        });
      }
    });
  } else {
    for (var i = 0; i < len; i++) {
      str += rows[i].id;
      str += ",";
    }

    if (len === 0) {
      //请选择一条督办记录!
      $.alert(collaboration_workflow_label_pleaseChoose);
      return false;
    }

    str = str.substring(0, str.length - 1);
    $.confirm({
      'msg': collaboration_workflow_label_sureDelete,
      //确定要删除督办记录?'
      ok_fn: function ok_fn() {
        var sup = new superviseManager();
        sup.deleteSupervisedAjax(str, {
          success: function success() {
            for (var i = 0; i < rows.length; i++) {
              try {
                var _affairId = getSenderAffairId(rows[i].summaryId);

                closeOpenMultyWindow(_affairId);
              } catch (e) {}

              ;
            } //刷新列表


            searchFunc('delete');
          },
          error: function error(request, settings, e) {
            $.alert(e);
          }
        });
      }
    });
  }
} //显示办理情况


function showAffair() {
  var rows = grid.grid.getSelectRows();
  var len = rows.length;

  if (len === 0) {
    //请选择一条督办记录!
    $.alert(collaboration_workflow_label_pleaseChoose);
    return false;
  }

  if (len > 1) {
    //请选择一条督办记录!
    $.alert(collaboration_workflow_label_pleaseChoose);
    return false;
  }

  var _affairId = getSenderAffairId(rows[0].summaryId);

  var url = _ctxPath + "/supervise/supervise.do?method=showAffair&id=" + rows[0].summaryId + "&affairId=" + _affairId;
  var dialog = $.dialog({
    url: url,
    width: 820,
    height: 400,
    title: i18nHandingLable,
    //办理情况
    targetWindow: getCtpTop(),
    buttons: [{
      text: close_label,
      handler: function handler() {
        dialog.close();
      }
    }]
  });
} //定义回调函数


function rend(txt, data, r, c, col) {
  //催办流程未结束
  function hastenRunningRFn() {
    return "<a class='noClick' href='javascript:void(0)' onclick='showSuperviseLog(\"" + data.id + "\")'>" + txt + superviseDetailList_secondary + "</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' class='ico16 notify_16 noClick' " + "onclick='showSuperviseDigram(" + "\"" + data.caseId + "\",\"" + data.processId + "\",\"" + data.isTemplate + "\",\"" + data.appName + "\",\"" + data.flowPermAccountId + "\",\"" + data.defaultNodeName + "\",\"" + data.activityId + "\",\"" + supervise_hasten_label + "\"," + true + ",\"refreshWindow" + "\",\"" + data.formAppId + "\",\"" + data.formRecordId + "\")'></a>";
  } //流程


  function workflowRFn() {
    return "<a href='javascript:void(0)' class='ico16 process_16 noClick' onclick='showSuperviseDigram(" + "\"" + data.caseId + "\",\"" + data.processId + "\",\"" + data.isTemplate + "\",\"" + data.appName + "\",\"" + data.flowPermAccountId + "\",\"" + data.defaultNodeName + "\",\"" + data.defaultNodeLable + "\",\"" + data.activityId + "\",\"" + supervise_col_label + "\"," + false + ",refreshWindow" + "\",\"" + data.formAppId + "\",\"" + data.formRecordId + "\"," + true + ")'></a>&nbsp;";
  }

  if (app == '1') {
    //标题
    var subjectRFn = function subjectRFn() {
      //标题列加深
      txt = "<span class='grid_black'>" + txt + "</span>"; //加图标
      //重要程度

      if (data.importantLevel != "" && data.importantLevel != 1 && data.importantLevel != "null" && data.importantLevel != null && data.importantLevel != -1) {
        txt = "<span class='ico16 important" + data.importantLevel + "_16 '></span>" + txt;
      } //附件


      if (data.hasAttachment === true) {
        txt = txt + "<span class='ico16 affix_16'></span>";
      } //协同类型


      if (data.bodyType !== "" && data.bodyType !== null && data.bodyType !== "null" && data.bodyType !== "10" && data.bodyType !== "30") {
        txt = txt + replaceOfficIcon(data.bodyType);
      } //流程状态


      if ($.trim(data.state) !== "" && data.state != null && data.state != "null") {
        txt = "<span class='ico16  flow" + data.state + "_16 '></span>" + txt;
      }

      return txt;
    };

    var replaceOfficIcon = function replaceOfficIcon(typeStr) {
      var bodyType = "";

      switch (typeStr) {
        case "HTML":
          bodyType = "10";
          break;

        case "FORM":
          bodyType = "20";
          break;

        case "OfficeWord":
          bodyType = "41";
          break;

        case "OfficeExcel":
          bodyType = "42";
          break;

        case "WpsWord":
          bodyType = "43";
          break;

        case "WpsExcel":
          bodyType = "44";
          break;

        case "Pdf":
          bodyType = "45";
          break;

        case "Ofd":
          bodyType = "46";
          break;
      }

      if (bodyType == "10") {
        return "";
      } else {
        return "<span class='ico16 office" + bodyType + "_16'></span>";
      }
    }; //当前待办人


    var currentNodeRFn = function currentNodeRFn() {
      return "<a class='noClick' href='javascript:void(0)' onclick='showSuperviseDigram(" + "\"" + data.caseId + "\",\"" + data.processId + "\",\"" + data.isTemplate + "\",\"" + data.appName + "\",\"" + data.flowPermAccountId + "\",\"" + data.defaultNodeName + "\",\"" + data.defaultNodeLable + "\",\"" + data.activityId + "\",\"" + supervise_hasten_label + "\"," + false + ",refreshWindow" + ",\"" + data.formAppId + "\",\"" + data.formRecordId + "\")'>" + txt + "</a>";
    }; //流程期限


    var processDeadlineRFn = function processDeadlineRFn() {
      if (data.workflowTimeout == true) {
        var tip = overtop_true_title;
        txt = "<span class='color_red'  title='" + tip + "'>" + txt + "</span>";
      } else {
        var tip = overtop_false_title;
        txt = "<span title='" + tip + "'>" + txt + "</span>";
      }

      return txt;
    }; //督办期限流程结束


    var superviseDeadLine4FinishedRFn = function superviseDeadLine4FinishedRFn() {
      if (data.isRed) {
        return "<span class='color_red'>" + txt + "</span>";
      } else {
        return txt;
      }
    }; //督办期限 未结束


    var superviseDeadLine4RunningRFn = function superviseDeadLine4RunningRFn() {
      if (data.isRed) {
        return "<a id='ssss" + data.id + "' class='noClick' href='javascript:void(0)' onclick='changeAwake(event,\"" + data.id + "\")'><span class='noClick color_red'>" + txt + "</span></a>";
      } else {
        return "<a id='ssss" + data.id + "' class='noClick' href='javascript:void(0)' onclick='changeAwake(event,\"" + data.id + "\")'>" + txt + "</a>";
      }
    }; //催办流程已经结束


    var hastenFinishedRFn = function hastenFinishedRFn() {
      return "<a class='noClick' href='javascript:void(0)' onclick='showSuperviseLog(\"" + data.id + "\")'>" + txt + superviseDetailList_secondary + "</a>";
    };

    var superviseSummaryRFn = function superviseSummaryRFn() {
      //督办摘要
      var summaryId = data.summaryId;
      var id = data.id;
      return "<a href='javascript:void(0)' class='noClick' onclick='superviseContent(\"" + summaryId + "\"," + data.status + ",\"" + id + "\")'>" + superviseDetailList_content + "</a>";
    };

    if (col.name == 'currentNodesInfo') {
      return currentNodeRFn();
    }

    if (col.name == 'deadlineName') {
      return processDeadlineRFn();
    }

    if (col.name == 'awakeDate') {
      if (data.status == 1) {
        return superviseDeadLine4FinishedRFn();
      } else {
        return superviseDeadLine4RunningRFn();
      }
    }

    if (col.name == 'count') {
      if (data.status == 1) {
        return hastenFinishedRFn();
      } else {
        return hastenRunningRFn();
      }
    }

    if (col.name == '_workflowbutton') {
      return workflowRFn();
    }

    if (col.name == 'title') {
      return subjectRFn();
    }

    if (col.name == '_summarybutton') {
      return superviseSummaryRFn();
    }
  } else {
    /*开始*/
    //当前待办人
    var _currentNodeRFn = function _currentNodeRFn() {
      return "<a class='noClick' href='javascript:void(0)' onclick='showSuperviseDigram(" + "\"" + data.caseId + "\",\"" + data.processId + "\",\"" + data.isTemplate + "\",\"" + data.appName + "\",\"" + data.flowPermAccountId + "\",\"" + data.defaultNodeName + "\",\"" + data.activityId + "\",\"" + supervise_edoc_label + "\"," + false + ",refreshWindow" + ",\"" + data.formAppId + "\",\"" + data.formRecordId + "\")'>" + txt + "</a>";
    };
    /*结束*/


    //公文使用一套 不再区别A8和G6
    if (c == 1) {
      if (data.appName == 'edocSend' || data.appName == 'govdocSend') {
        txt = docmark_inner_send;
      } else if (data.appName == 'edocRec' || data.appName == 'govdocRec') {
        txt = docmark_inner_receive;
      } else if (data.appName == 'edocSign' || data.appName == 'govdocSign') {
        txt = docmark_inner_signandreport;
      } else if (data.appName == 'govdocExchange') {
        txt = docmark_inner_exchange;
      }
    }

    if (c == 2) {
      //加图标
      //重要程度,公文有自定义重要程度
      if (data.importantLevel != "" && data.importantLevel > 1 && data.importantLevel < 6) {
        // txt = "<span class='ico16 important"+data.importantLevel+"_16 '></span>"
        // + txt;
        // 这里使用input标签的是为了不让父标签的title属性识别到重要程度标识中的文字，例如：平急、加急、特急、特提
        if (data.importantLevel === 2) {
          txt = "<input class='important-level important-level-2' style='float: left;color: white;' readonly='readonly' value='" + $.i18n('govdoc.quick.normal') + "'/>" + txt;
        } else if (data.importantLevel === 3) {
          txt = "<input class='important-level important-level-3' style='float: left;color: white;' readonly='readonly' value='" + $.i18n('govdoc.quick.expedited') + "'/>" + txt;
        } else if (data.importantLevel === 4) {
          txt = "<input class='important-level important-level-4' style='float: left;color: white;' readonly='readonly' value='" + $.i18n('govdoc.quick.express') + "'/>" + txt;
        } else if (data.importantLevel === 5) {
          txt = "<input class='important-level important-level-5' style='float: left;color: white;' readonly='readonly' value='" + $.i18n('govdoc.quick.teti') + "'/>" + txt;
        }
      } //附件


      if (data.hasAttsFlag === true) {
        txt = txt + "<span class='ico16 affix_16'></span>";
      }

      var bodyType = '10';

      if (data.bodyType == "OfficeWord") {
        bodyType = 41;
      } else if (data.bodyType == "OfficeExcel") {
        bodyType = 42;
      } else if (data.bodyType == "WpsWord") {
        bodyType = 43;
      } else if (data.bodyType == "WpsExcel") {
        bodyType = 44;
      } else {
        bodyType = data.bodyType;
      } //附件


      if (data.hasAttachment === true) {
        txt = txt + "<span class='ico16 affix_16'></span>";
      } //协同类型 HTML不显示图标


      if (bodyType !== "10" && bodyType !== 'HTML') {
        txt = txt + "<span class='ico16 office" + bodyType + "_16'></span>";
      } //流程状态


      if ($.trim(data.state) !== "" && data.state != "0") {
        txt = "<span class='ico16  flow" + data.state + "_16 '></span>" + txt;
      }

      return txt;
    } //已办结


    if (superviseStatus == '1') {
      if (col.name === "currentNodesInfo") {
        return _currentNodeRFn();
      }
    } else {
      //未办结
      if (col.name === "currentNodesInfo") {
        return _currentNodeRFn();
      }
    } //督办期限


    if (col.name === "awakeDate") {
      if (data.status == 1) {
        if (data.isRed) {
          return "<span class='color_red'>" + txt + "</span>";
        } else {
          return txt;
        }
      } else {
        if (data.isRed) {
          return "<a id='ssss" + data.id + "' class='noClick' href='javascript:void(0)' onclick='changeAwake(event,\"" + data.id + "\")'><span class='noClick color_red'>" + txt + "</span></a>";
        } else {
          return "<a id='ssss" + data.id + "' class='noClick' href='javascript:void(0)' onclick='changeAwake(event,\"" + data.id + "\")'>" + txt + "</a>";
        }
      }
    }

    if (col.name == "deadlineName") {
      //流程期限
      if (data.workflowTimeout == true) {
        var tip = overtop_true_title;
        txt = "<span class='color_red'  title='" + tip + "'>" + txt + "</span>";
      } else {
        var tip = overtop_false_title;
        txt = "<span title='" + tip + "'>" + txt + "</span>";
      }

      return txt;
    }

    if (col.name == "count") {
      if (data.status == 1) {
        return "<a class='noClick' href='javascript:void(0)' onclick='showSuperviseLog(\"" + data.id + "\")'>" + txt + superviseDetailList_secondary + "</a>";
      } else {
        return hastenRunningRFn();
      }
    }

    if (col.name == "processDescBy") {
      return "&nbsp;<a href='javascript:void(0)' class='ico16 process_16 noClick' onclick='showSuperviseDigram(\"" + data.caseId + "\",\"" + data.processId + "\",\"" + data.isTemplate + "\",\"" + data.appName + "\",\"" + data.flowPermAccountId + "\",\"" + data.defaultNodeName + "\",\"" + data.defaultNodeLable + "\",\"" + supervise_edoc_label + "\",\"" + "\",\"" + "\",\"" + data.formAppId + "\",\"" + data.formRecordId + "\"," + true + ",\"" + data.summaryId + "\"" + ");'></a>&nbsp;";
    }

    if (col.name == "description") {
      var summaryId = data.summaryId;
      var id = data.id;
      return "<a class='noClick' href='javascript:void(0)' onclick='superviseContent(\"" + summaryId + "\"," + data.status + ",\"" + id + "\")'>[内容]</a>";
    }

    if ("${ctp:escapeJavascript(param.status)}" == '1') {
      if (col.name == "processDescBy") {
        var summaryId = data.summaryId;
        var id = data.id;
        return "<a class='noClick' href='javascript:void(0)' onclick='superviseContent(\"" + summaryId + "\"," + data.status + ",\"" + id + "\")'>[内容]</a>";
      }
    } else {
      if (col.name == "processDescBy") {
        var id = data.id;

        if (data.status == 1) {
          return "<a class='noClick' href='javascript:void(0)' onclick='showSuperviseLog(\"" + data.id + "\")'>" + txt + "${ctp:i18n('supervise.superviseDetailList.secondary')}</a>";
        } else {
          return "<a class='noClick' href='javascript:void(0)' onclick='showSuperviseLog(\"" + data.id + "\")'>" + txt + "${ctp:i18n('supervise.superviseDetailList.secondary')}</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' class='ico16 notify_16 noClick' onclick='hastenRunningRFn()'></a>";
        }
      }
    }
  }

  return txt;
} //刷新页面


function refreshWindow() {
  window.location.reload();
}

function getSenderAffairId(summaryId) {
  var _affairId = 0;

  var _superviseManager = new superviseManager();

  var objSum = _superviseManager.getSenderAffair(summaryId);

  if (null != objSum && objSum.affairId != null) {
    _affairId = objSum.affairId;
  }

  return _affairId;
}

function getCurrentTime() {
  var date = new Date();
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var day = date.getDate();
  var hour = date.getHours();
  var time = year + "-" + month + "-" + day + " " + hour + ":" + "00";
  return time;
}

function getCurrentDate() {
  var date = new Date();
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var day = date.getDate();
  var date = year + "-" + month + "-" + day;
  return date;
}

var changeAwakeID;

function changeAwake(e, id) {
  changeAwakeID = id;
  var time = getCurrentTime();
  var maintop = parseInt($(getCtpTop().document).find(".layout_content").css("top"));
  var left = (getCtpTop().document.documentElement.clientWidth - 295) / 2;
  var top = (getCtpTop().document.documentElement.clientHeight - 260) / 2 - maintop;
  $.calendar({
    displayArea: "ssss" + id,
    position: [left, top],
    returnValue: true,
    ifFormat: "%Y-%m-%d %H:%M",
    daFormat: "%Y-%m-%d %H:%M",
    dateString: time,
    singleClick: true,
    showsTime: true,
    onUpdate: getDateTime,
    autoShow: true,
    isClear: true
  });
}

function addUrlPath(urlStr) {
  var _url = urlStr;
  var _loca = window.location.href;

  if (_loca.indexOf("srcFrom=bizconfig") != -1) {
    //控制面包削
    _url += "&srcFrom=bizconfig&condition=templeteIds&templeteIds=" + $("#templeteIds").val();
  } //srcFrom=bizconfig&condition=templeteIds&templeteIds=4487748473006737914;


  return _url;
}

function getDateTime(awake) {
  var date1 = getCurrentDate();
  ;
  var date1s = date1.split("-");
  var bdate = new Date(date1s[0], date1s[1] - 1, date1s[2]);
  var date2 = awake.substring(0, 10);
  var date2s = date2.split("-");
  var edate = new Date(date2s[0], date2s[1] - 1, date2s[2]);
  var url = _ctxPath + "/supervise/supervise.do?method=modifySupervise&superviseId=" + changeAwakeID + "&awakeDate=" + awake + "&app=" + app;
  url = addUrlPath(url);

  if (bdate.getTime() > edate.getTime()) {
    var confirm = $.confirm({
      'msg': supervise_thisTimeXYouset,
      //您设置的督办日期小于当前日期,是否继续?
      ok_fn: function ok_fn() {
        document.location.href = url;
      },
      cancel_fn: function cancel_fn() {
        confirm.close();
      }
    });
  } else {
    document.location.href = url;
  }
}

function findListByStatus(status, flag, type, tempIds, bizConfigId) {
  location.href = _ctxPath + "/supervise/supervise.do?method=listSupervise&status=" + status;
} //催办日志


function showSuperviseLog(superviseId) {
  var url = _ctxPath + "/supervise/supervise.do?method=showLog&superviseId=" + superviseId;
  var dialog = $.dialog({
    url: url,
    width: 815,
    height: 500,
    targetWindow: getCtpTop(),
    title: supervise_col_title_label
  });
} //督办摘要


function superviseContent(summaryId, status, superviseId) {
  var url = _ctxPath + "/supervise/supervise.do?method=showDescription&summaryId=" + summaryId + "&superviseId=" + superviseId;
  var but = new Array();
  var dialogs = ""; //当是未办结状态时，才显示确定按钮

  if (status == 0) {
    but.push({
      text: ok_label,
      handler: function handler() {
        var returnValue = dialogs.getReturnValue();

        if (returnValue != null) {
          var map = $.parseJSON(returnValue);
          var content = map.content;
          var url = _ctxPath + "/supervise/supervise.do?method=updateContent&content=" + content + "&superviseId=" + map.superviseId;
          $("#grid_detail").jsonSubmit({
            action: url,
            callback: function callback() {
              setTimeout(function () {
                dialogs.close();
                window.location.reload();
              }, 10);
            }
          });
        }
      }
    });
    but.push({
      text: cancel_label,
      handler: function handler() {
        dialogs.close();
      }
    });
  } else {
    but.push({
      text: close_label,
      handler: function handler() {
        dialogs.close();
      }
    });
  } //显示title需要判断app


  var appName = app;
  var openTitle = supervise_col_label;

  if (appName == 4) {
    openTitle = supervise_edoc_label;
  } //督办摘要 弹出dialog


  dialogs = $.dialog({
    url: url,
    width: 500,
    height: 350,
    targetWindow: getCtpTop(),
    title: openTitle,
    buttons: but
  });
} //归档公文修改日志


function showArchiveModifyLog_iframe() {
  try {
    var rows = grid.grid.getSelectRows();
    var len = rows.length;

    if (len === 0) {
      //请选择一条督办记录!
      $.alert(collaboration_workflow_label_pleaseChoose);
      return false;
    }

    if (len > 1) {
      //请选择一条督办记录!
      $.alert(collaboration_workflow_label_pleaseChoose);
      return false;
    }

    var summaryId = rows[0].summaryId;
    var url = _ctxPath + "/edocController.do?method=showArchiveModifyLog_Iframe&summaryId=" + summaryId;
    var dialog = $.dialog({
      url: url,
      width: 750,
      height: 550,
      title: i18nEdocArchiveModifyLable,
      targetWindow: getCtpTop(),
      buttons: [{
        text: close_label,
        handler: function handler() {
          dialog.close();
        }
      }]
    });
  } catch (e) {}
}

function editEdocWorkflow(finished, caseId, processId, isTemplate, appName, flowPermAccountId, defaultNodeName, defaultNodeLable) {
  if (finished == 'true') {
    $.alert(collaboration_process_finished);
    return;
  }

  superviousWFCDiagram(getCtpTop(), caseId, processId, isTemplate, window, appName, flowPermAccountId, defaultNodeName, defaultNodeLable, supervise_edoc_label);
}

function showSuperviseDigram(caseId, processId, isTemplate, appName, flowPermAccountId, defaultNodeName, defaultNodeLable, title, showHastenButton, closeCallBack, formAppId, formRecordId, canEditWorkflow, summaryId) {
  var NPS = "default";

  if (appName == "govdocSend" || appName == "govdocRec" || appName == "govdocSign" || appName == "edocSend" || appName == "edocRec" || appName == "edocSign") {
    NPS = appName;
    appName = "edoc";
  }

  var showTitle = supervise_col_label;

  if (title != null && title != "" && title != "undefined") {
    showTitle = title;
  }

  var dialogBtns = [];

  if (typeof canEditWorkflow != "undefined" && canEditWorkflow == true) {
    dialogBtns.push({
      "id": "modify",
      "callBackFn": closeCallBack
    });
    dialogBtns.push({
      "id": "saveDBOK",
      "callBackFn": searchFunc
    }); //修改流程之后,刷新页面(刷新当前待办人等信息)
  }

  if (showHastenButton) {
    dialogBtns.push({
      "id": "close",
      "callBackFn": searchFunc
    });
  } else {
    dialogBtns.push({
      "id": "close"
    });
  }

  if (formAppId == null || formAppId == "null") {
    formAppId = "";
  }

  if (formRecordId == null || formRecordId == "null") {
    formRecordId = "";
  }

  var options = {
    targetWin: getCtpTop(),
    caseId: caseId,
    processId: processId,
    isTemplate: isTemplate,
    appName: appName,
    flowPermAccountId: flowPermAccountId,
    defaultPolicyId: defaultNodeName,
    defaultPolicyName: defaultNodeLable,
    title: showTitle,
    scene: 3,
    SPK: "freeFlow",
    NPS: NPS,
    showHastenButton: showHastenButton,
    isAdminMangerModel: true,
    buttons: dialogBtns,
    masterId: formRecordId,
    formAppId: formAppId
  };

  if (typeof summaryId != "undefined") {
    var secretLevelValue = callBackendMethod("secretAjaxManager", "getFileSecretLevel", summaryId);
    options.accessFileSecretLevel = secretLevelValue;
  }

  showDiagram(options);
} //二维码传参chenxd


function supervise_detail_precodeCallback() {
  var obj = getSearchValueObj();
  obj.openFrom = "supervise";
  return obj;
}

function getSearchValueObj() {
  var o = new Object();
  var choose = $('#' + searchobj.p.id).find("option:selected").val();

  if (choose === 'title') {
    o.title = $('#title').val();
  } else if (choose === 'importantLevel') {
    o.importantLevel = $('#importantLevel').val();
  } else if (choose === 'sender') {
    o.sender = $('#sender').val();
  } else if (choose === 'sendDate') {
    var fromDate = $('#from_' + choose).val();
    var toDate = $('#to_' + choose).val();
    o.sendDate = '';
    o.begin_sendDate = fromDate;
    o.end_sendDate = toDate;
  } else if (choose === 'deadlineDatetime') {
    //流程期限
    var fromDate = $('#from_' + choose).val();
    var toDate = $('#to_' + choose).val();
    o.deadlineDatetime = '';
    o.begin_deadlineDatetime = fromDate;
    o.end_deadlineDatetime = toDate;

    if (fromDate != "" && toDate != "" && fromDate > toDate) {
      $.alert(collaboration_rule_date); //开始时间不能早于结束时间

      return;
    }
  }

  if (window.location.href.indexOf("condition=templeteAll&templeteAll=templeteAll") != -1) {
    o.templeteAll = "templeteAll";
  }

  o.status = $('#status').val();
  o.app = app;
  o.templeteIds = templeteIds;
  return o;
}